#include <bsl_err.h>
#include <bsl_sal.h>
#include <crypt_algid.h>
#include <crypt_eal_md.h>
#include <crypt_eal_pkey.h>
#include <crypt_eal_provider.h>
#include <crypt_errno.h>
#include <crypt_rsa.h>
#include <crypt_params_key.h>
#include <securec.h>

#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>

#include <cmocka.h>

#include "helper.h"
#include "test_rsa.h"
#include "kaep_err.h"

#define GROUP_TEST_MAX 100

#define CRYPT_EAL_PKEY_KEYMGMT_OPERATE 0
#define CRYPT_EAL_PKEY_CIPHER_OPERATE  1
#define CRYPT_EAL_PKEY_EXCH_OPERATE    2
#define CRYPT_EAL_PKEY_SIGN_OPERATE    4

typedef struct {
    int32_t keyLen;
    int32_t padMode;
    int32_t hashId;
    char *n;
    char *e;
    char *d;
    char *plaintext;
    char *ciphertext;
    char *label;
} RSA_Enc_Test;

static CRYPT_EAL_LibCtx *CreateLoadLibCtx()
{
    CRYPT_EAL_LibCtx *libctx = CRYPT_EAL_LibCtxNew();
    assert_non_null(libctx);
    assert_int_equal(CRYPT_EAL_ProviderSetLoadPath(libctx, "../../build"), CRYPT_SUCCESS);
    assert_int_equal(CRYPT_EAL_ProviderLoad(libctx, BSL_SAL_LIB_FMT_LIBSO, "kae_provider", NULL, NULL), CRYPT_SUCCESS);
    return libctx;
}

static void SDV_KAE_RSA_ENC_PROVIDER_LOAD(void **state)
{
    (void)state;
    CRYPT_EAL_LibCtx *libctx = CreateLoadLibCtx();
    CRYPT_EAL_LibCtxFree(libctx);
}

static RSA_Enc_Test SDV_KAE_RSA_CRYPT_FUNC_TC001_VEC[] =
    {
        {
            1024,
            CRYPT_CTRL_SET_RSA_RSAES_OAEP,
            CRYPT_MD_SHA1,
            "cf473a4d9bfffc47b4512f26e4498928cc9f27349badaf115e76be7d08941d6a2bb6aa54767af279a7087edbed9bbc23176ea6862dadf79ab0af34a8c5b4b453c037093bbb432376234fe9d3954a764c2a05f91d505fd18a6223eca1c4e3c926e72684d4c9148ba6ef3e448b27a4576240363ce8d850a9d4cff67a6affd1008b",
            "03",
            "8a2f7c33bd5552da78361f6f42dbb0c5ddbf6f7867c91f60e9a47efe05b8139c1d24718da451f6fbc4b054929e67d2c20f9f19aec91ea511cb1f787083cdcd8bf60989f1d650d42c40d201d9c70fb408fe8b6fc661712af3a0ae006c5d90fa5dee974dade64873c9ba430b18ecd18bdd2995731dead6c30e816b69e27dc20f0b",
            "54657374",
            "c904ed383f834085134fcdc2d2042fa487a56c6816c334ebf9f3d852e435714fa60f42741cc9982694b2ec34fb21df553a9e8d70513650cdaa72ddecd9533ef34f7364c8bd3e5c20c5aef490ad5be0612b7e7c9f9a6d579a6ad38446f9eb3ab5ffe56ee34f27c510e4a871f0ad1479d0a641402f46efa1cf700ef0a1c06139ad",
            NULL,
        },
        {
            2048,
            CRYPT_CTRL_SET_RSA_RSAES_OAEP,
            CRYPT_MD_SHA1,
            "c1c37d104ad39a6a41979b7bc2d696481e2c55564204c26631ee726c7d75fa3a3887948c84307e96564fcfcdf3c7df9c441547449e656b9e60542ac18557991dfe0a5977ec3b652b9791e4e6e2afa790d4d6fa178070084b638cbee8ab2554f3b3db6789c5cd0abd6fa8c8e6026fcceb0a20f1513a80a98ad8be464f0e8a1bb3753d384ba0bca778aec4c5b24e7b41fc305298f0add734fc5f2fbcf5ac4703954673256a4b6bae93e9f2434185327df046aabc4e56989c6e32aafb03fecd19db519db5236f4445da2d1bcf99a916250fe8b6678f19ab48f1d62c2e1fd031305cc0bd4ee15ea1695d2f5d8ca5dd99064f31b8ae61c3617e0f1b6974aafbfea71f",
            "03",
            "812cfe0adc8d119c2bba67a7d739b9856972e38ed6add6eecbf44c4853a3fc26d05a630858205464398a8a894d2fea682d6384d86998f269958d71d658e510bea95c3ba5482798c7ba614344971fc50b388f5165004ab032425dd49b1cc38df7cd3cefb12e88b1d39fc5db44019fddf206c0a0e0d1ab1bb1e5d42edf5f06bd2124292795701b469e508288f5e62beda7d2569777d0262705be9f1633280133c75dd54987d5361d0068d055e0ed2c012ca5ac1d6bd5641a495abdb6c68fb4b20f007713f120130bf66283620231d9cfe8da81e5bbcdc98e3c8c31addca80847c377e7094f75cf1a5dde0c134078782a5cf9492506ebd21e8a82b17e3eb019667b",
            "54657374",
            "2b2754e78c89fd44f0dde4781e58f1f2c115dbd1fec6be2d9c189db77619f5ef5cb57fd40f71124a35a5048ce633ba4d590fcb0660555acb9e040db3913aa1439755c922a395aa43711f77685f613613a9507e42d09d26837173b35f76aff877c036ffcf7d8736d6f9c52ebe594ab0f95f571083b88a24d48d701bb321bf387cda53224a4096dd42c9effcbc6535b2ff4802be62a06db7eaadbaafb7f787a466c766d96c8b084d532d2065100b13f465f500f03d8e76a4d415cc69e969cf7eef24cb153347d6e53257c4d69165f86caa04d26d8cb72712fd07e6264e109d8316fe4c2949c94ac0ba9ea75dd64e704710f9655620c5335a2e9c07ffe07f9f8d62",
            NULL,
        },
        {
            3072,
            CRYPT_CTRL_SET_RSA_RSAES_OAEP,
            CRYPT_MD_SHA1,
            "b10f2427606bc476864c97060c4738d8cce100596baa54517bc5965bf8867901be733dca7c29a8e0cd91bc085d954dc0f8ae1f2a9c136928613c8b51013f8383df1d9f6b73ff449d990e18d007ca244d922811c06e90d639442d6363d3b9094d5884cae7d31cd833a1e543c5c1fe3c288bccbbd245ff9036c39756f7ed687c3d233c87dd6f538be7c375eb3c4199a8231e386fd97bd86de245a57eceb8623d2644d283a6e4d486e231b3e13dc857396e9a47e70e5fd99cf2d3185224679743db4aab4c7a8c030505d92f9f50940176439428e20e8caff3007340b8be2ff570ba1e23693b31ea542c527d6f4e8eeb95a21989beaa393382aa276aa7feebb378d0e18300bf481cea0856762d4b70f378224c13998854566eddfcb89489e814d7022242e4deada4a58707aa38046ea42292399c13c0af60a4b0acb0936b874274692906ffd53702536f49afa7e574ca325e93b61154b2871a9c527feaa539439b23ee0de7962d2dba5101add1155be79842fab2dc0697849f7fa61c06908cac7323",
            "03",
            "760a181a4047d84f04330f595d84d0908896003b9d1c38365283b992a5aefb567ef77e86fd711b40890bd2b03e63892b507414c712b79b7040d3078b562a57ad3f6914f24d54d86910b4108aafdc1833b6c5612af4608ed0d81e42428d26063390588745376890226bee2d2e8154281b07ddd28c2eaa60248264e4a548f052d36cd3053e4a37b29a824e9cd2d6667017697af53ba7e59e96d918ff347aec28c42de1ad19ede30496cbcd40d3dae4d0f466da9a09953bbdf737658c18450f829115771a0aadfc9c5f69248379ef968e44353689103d41ef5405ca7475280d2c259c42d43c88fc992c54a51a17c7982a7d5d404b399478a16f1ea5b5de9ea171ac579ad1e2e8c75b86f37ca9f030642b155d6e9d67e27c99f3f78d515402133e6aa6408ebe92754f8fd4e70aedb6dc9b0cad9585109908ddb5af9b872ac7ed4247f82b8fd4cda2578533a58f0fc8bb1c5c7ebec7b3ce193462aa5efe5e5cf9eb02e3ff8a09baf7fbbfa0a155406396f141ed50d84c089ad1e8b579956b728a7c0b",
            "54657374",
            "9b5eb3fec17cd558ba0ef9137805348ae014f3483a3a1597bf08fafcfe8f0d75cf586f0b495c799cc3179754c63fd306b430a8b624ba52e1c00bf1dafdbdb709538a4f2737a8073b5e97114c49acd4e7fe364cb55bca754c1babe4487bbf4d96f812a3989ce1932a82385957c5ee5b71d14fe2e8d6cc4bced40d067d456ca1df097a93ace293dfeb57371ad56003c7eeb37127a53de99ac4e7a1dd52a3afdee4d1b996f4a9db8d9685c864f96e85d857d696998d702b200a83c90afdb2a01c18413d095c53f5b4d139312f881cfa315e901474030b13f53e2ead1ebcaf0f22adf09aa188fb297b8688f2628b28331a322d460c851eba418ab770491165b420722ae3c2750c48c9b7c42dc861590b0906abb6978f24a24dca56cd3e5a06812a76cad20e6545768f2d315e98fe1be8a02042c7be81207b808dcfe2f1ec476437fd3c7c52a188ab0379ae4567f104c39db5c1bacf6aeec56dc29df29ac7dcdf363b1faddd56d2377b897ca715a65cfdc5b2551d5882c9a7f37d59947ead032d2b2c",
            NULL,
        },
        {
            4096,
            CRYPT_CTRL_SET_RSA_RSAES_OAEP,
            CRYPT_MD_SHA1,
            "b8b2266f82b03e0ae3f75461f264a23521719f7ed92db85758db6d6fa78db7fb94781522e7494f228daf8af2c98b785facb7c32bfba2f8d609d13e80aaffea5f910ff0e3c2e3d6ea2a0801e741f718188022b776e71cdbe7f5adb41abb2b86fe8875eb527bfb4e1d57e42e7694a0cff8a037788647d82c2c6bbf7f623aa0393bb11678a9f50dbf96c566ce4f0b26d49e2e49097519bd9b86848cd386fa5377f596819497c1db24fcd3c369874f7061b4e91b39caf9cf8ef80506c7f56f6619d6f0a4226238a295936d7f5d4b4806e4c15a8b459cd31184b59508cf9b404988487083fa58b5847e0d29a64f854277e1314c89f39833441a866644af757adae6423444c10f65c6cb51cd26394cb0ed6a238336fec471539b943692f3fdcc712b967813a2a71f5a437e33384314fb02b9656a08d59be930f9337f6cac177bf714092b9b5981b2ab4e9e6d1f2f6d8f31687415341103f6f78330c12f86db1c232da3daaa9a1d5792c9e9e94e93acb05f34468d50ff435949174cd4c211db5ca190358ad33ced3f5e3ffc7d8158f48cc94b52d1d85adb725c9e3903705871a6e4a84f72f3f51fe70e422e3a63050497750e52e1e27bc9e0862e4dfaec6c5d6e44773afddb4d12b2964cf1a89a804c5734c73f58a08107ae8c57ee2260604ff77d60a28490d8b4c558ff298ada5ada896d16eee89a9948cc0263ca50db6131fdced449",
            "03",
            "7b216ef501cad40742a4e2ebf6edc178c0f66a5490c9258f909248f51a5e7aa7b8500e1744db8a17091fb1f73107a5951dcfd772a7c1fb395be0d455c75546ea60b54b4281ed39f1715aabef814f6565aac1cfa49a133d454e73cd67277259ff05a3f236fd5234138fed744f0dc08aa5c024fb042fe572c847d4ff96d1c02627cb6450714e092a648399dedf5cc48dbec986064e11291259adb337af518cfaa3b9abb8652be76dfde282465a34f596789b677bdca68a5f500359daa39f99668f4b1816ec25c1b90cf3aa3e3230049880e70783bde20badce635b35122adbb0304b02a6e5ce585408c66edfae2c4feb763306a2657782bc5999831fa3a73c9980558ec57e442a5c73126b30843d0c153b36238f1bae3a26da4f77c1fd4acc0ec7fec9e48eca2bf494e5c3bf3cd65cb73900d93f876abeef8865b5a2a3877cc1aabdefa7b6bb7c7175050abddd5ca5901c928e4cab5df49038402377972d79338a40c59b5d37e2914bf191be440db793fe070ebaaa23686044e7a1f164c813ea7626ddefb738301a4d8e4ed18df8e2cc5748f7efc39e224df0c2cdf3a1054ddea0a8d7dfa4671a9843edf31700b28391d3bd690dbca05945068bbf22bbc6c5178332f961a9a7a83551752bd3c7041c6c5987faf3443a89847eebdc53aeb77c6573e65c675d3e71752bf10dd2d11c15804c8128924ef8f90bebab3472a17664920b",
            "54657374",
            "2336c74430608f924a7858f5134283e346131794b59fcae01c2fcfeaeda90aea1a6f5fb3d74a6f1008c6b791d6ecdb41a582a556d4617a88ecbbacd8c95f91059237e576ae6392aca39e9a222dd103492196abaada486be0343fa80803e0891449b03626d5a9f86f3bd9cb234d2988fe33cbf81ef46bd57e9719ea2292178cc487b025ea5f11823ffffcf99359ecccb9d00806370549a73e7a67165f1dce6b408ada3d8aae6307fbb41922ccd80e6ab1d96d8cf0678083c5ccb3367682dbc375ebeaf9624aaae9c9481c83ba7cb91d10f100e7fd23f94c3be196e8701d4dd6c117cf73e7bd8d27630d091862aa9af7695dcce821b9314241a85cd238a27ddd68085e087ce485b5e4bd5b5caa0525a2cf46f999a668d0c45442330e0f009ece0cfd3e025dad13f26fdab206d9445f8bddd17c0228acfae75b03dab42597b6d113ecb09411c11c36503a2d7db7fab579e25b3031b9d609618bd8f664d0d8760e9b6a8705b87890dff8fe7ce72dc0bfae53f22f5c994d379e089bf7de01b092ae328d0926fce2e5ddc4381daf2cea7bf6a8a75c45ea5487e435d2b4ea9ffa7f9c8387a0783f2f349f4bd9abd6d8b97f604e35252cab40253bcec7f98c26817a976c27a8cea58cfb2d96b602226260f132a85f95f39aa8b4f542287cc7b8126ec8c8d9916fc6cf0b9f17f72dd50605277d283cf5b734989b91cfdf2b14ea737bd8dd",
            NULL,
        },
        {
            1024,
            CRYPT_CTRL_SET_RSA_RSAES_PKCSV15,
            CRYPT_MD_SHA1,
            "b8a1d57c120046e1d889be1548c14c9768a3f503e0813e369eee1c5c6dc775c70ccad62eb0be48c143e1786fdae35291818e35c9620db6299eccc34fe8dd8f8f1f1b0e1547fc6c7be8f3687ac58dd6f3a4b41aae9c965d3386ccb6087d3be63fa0fc2e6cf0ddcf84f51d2a1ade096f07e3140f1b1ab08897e0b69246f975b251",
            "03",
            "7b168e52b6aad9ebe5b1296385d6330f9b17f8ad40562979bf49683d9e84f92f5ddc8ec9cb2985d62d40faf53c978c6101097930ec09241bbf332cdff093b508f18ea897df42cab2bc5395dc9879b5e5ed1551d768c5970ca7ce36e56837b14f31f6d08afa359e6839bd597c05d23eb572eaf4fe15b96a695cd8bcc09329c1c3",
            "0fe6fcde58648f13ebd5f0ccbd68458da8ae18dfbe82238d2fb90eb42b743dcbe7b12b33f77e31ca85eaf694dcc1159c2fd4778fce93ceca25f5123aa63ad8ddbf776400d489d8d3d46665c9d22b4382",
            "3ff4bb04905691356e627f29a0aa2ea98ae6f778c11b6f746a6f636ab3420f1e4692efb66c8ab4d436a30b14f0b4c0403a0fc12585e4724d000f8a29054c785f51b38fdae5ba2e3d2de4cfe7f3c01eb1a0d8564a0f7f8cbe83c51024680767350fe0cf7cceab2bb8ec8fda1afbf651029e83bca93a7c6003a876835cd0b8ad74",
            NULL,
        },
        {
            2048,
            CRYPT_CTRL_SET_RSA_RSAES_PKCSV15,
            CRYPT_MD_SHA1,
            "a01b12f4f85e165338f307fa12b80a15d400b2c41de93368ec64be7308ea4dba3902256172edfdf0bef6bad0105806fcacca64b8dbb79f7546302d35f4adb03ed8d01f794a2faa2ec509593724a7963c3f60944dbd1d1a685d3f73e39ec956df3291319dd8697fd0f94a807ae2ebc6846a8d98ff80112a7f372e820f8cc7467703d5718cce913cee5312facfa98635eec50d9f1c286e7d388e6f0da456852fc51095b8e50ad7d9340ab177a5503ca7559928193a7cfe070c80dd1a0388383b79c857b4d16261b84b4e82adf109041561fffd866e9b84e286117796734abebbf3dadb7e8d5356fc1214ecc7074de5f14956ef077fdff21e0093c5cbda50c52821",
            "03",
            "6abcb74dfae964377b4caffc0c7ab163e2ab21d813f0ccf09d987ef75b46de7c26016e40f74953f5d4a47c8ab59004a87331987b3d2514f8d97573794dc92029e5e014fb86ca7174835b90cf6dc50ed2d4eb0d8928be119ae8d4f7ed148639ea21b62113e59baa8b50dc55a741f28458470910aa5560c6ff7a1f015fb32f844e49f06beb68f7e6490fdf2c90e19f91fbd8ed8e42e6a8d0d1bf4086208e4b269a4b8378584c43cfc2027a174066615f8f47c9a36b2c9931ad556b047906939513f2194d4d39cc05ae4d8040d186d0d84773b9ace785fb9705bb12c595da22cd4fb15f715a40dbfa9c9d06724af23302dd534925829ed0fe3ccae268bb811c1583",
            "54657374",
            "931a0c8083ce1289b232a0d41523a4d50b5610ab47bfe5b95f40667fd3c9a3b4ec7915828461d09f826d241c1ee056ea7ce41d00c04490269aff9158643e4a4b1deea7b6139f65a9eec3bd1c692206002670e46b4ffbf9521fe08cb74aa3d3ac16beb5d594f25c01e9b5d6eebe5df8b9812e90b602f4a3311b63282e63b0f76ef16f5d8c46d7202cd2da7cb8fd7b9df73bfb1ac61929f5e69dc28ec23304d15ccf5ec9e14c5fd9a5914e88876c26180616a8fe6d33b7694aa79b72dcac80eca5d31e6c65470b2d520631701288869c37f4494ce35dabb7fbf946526d0ed611038fe62c934c320348015a6a415eccec9049dfc1cc6feba33f18a49751037b2694",
            NULL,
        },
        {
            3072,
            CRYPT_CTRL_SET_RSA_RSAES_PKCSV15,
            CRYPT_MD_SHA1,
            "a863f275f36d454a21a3abb9ada2cfc93300065352de66155e32f5fbc2917f83b469f4a3d41c0891994a467df51a723d1d0ca4e04346f9cfec56774e4d1f96fc37d885fde675387de98e732c41755ffa305f138b713b98b88b63a2c5cf1adce5fd1bd4857b136cbb6ab27a6f0f37dc0658279fc0af07ce0f9ddff5a89dc692498c3d2fcfb3a58a7072e5f017af9e24ce7ada68cc0f1c56d7f47dd82d779532fa09e7820c449f642566fe2f2d3a5bbc609db8c09fc7b5839a6398c49063dc96456f27ba108c5ea8bd4d477357081dc2258e5f5c2d4306d946a136d66baaa3e0d6955664ecbfb0140d9ceb87c8212a49cc276a1112518685e30b5b3147a92b6c0d135c0b205d52b5b42c7d46741c0d4d712763a3bb952d8df43b79e10002d285a1ba4d8b2f535d16baf112041b3227e2d06011fef83347b7f10e5128767c5127f7a73de53b5988c94383a91d5c0f24eaa2267394d84c9e18912b1991c3f54675f81abf7ae356b1fbf55b825f0e8eec03937327a866a2b4fd7e01a6c025550664b1",
            "03",
            "7042a1a3f79e2e316bc2727bc9173530ccaaaee2373eeeb8e9774ea7d70baa57cd9bf86d3812b06110dc2efea366f6d368b31895822f51354839a4dede150f52cfe5aea9444e25a9465ef772d64e3ffc203f625cf627bb25b2426c83df673deea8bd3858fcb79dd24721a6f4b4cfe8043ac5152b1f5a895fbe954e70692f0c310828ca8a77c3b1a04c994aba75141889a73c45dd5f6839e54da93ac8fa6377515befac082dbf9818ef541f737c3d28406925d5bfda790266ed10830aed3db9828a825489613116ec8c16819630b207fb8e72129dcc53a53a8babf6045090550393859a83fd5945248964b2ce996398bce0e3e88b58bed6b678002a800a183138534757c54c45b82389a51c854137fdf92f2821571778c1c94e416e064af1c595034ec2817a12cf20c785630660c24f4d2b683b28dca8334138e0637db57ee7df38c7fe5f4bc4a3efc1a323ed55ffe34b90bf8c32d424e03ab5eacaf7e0697a843384f1bd43dec0db67d9f7f85678d25ba04f6dbcdbfca2ed5b836760e23bc6ab",
            "0fe6fcde58648f13ebd5f0ccbd68458da8ae18dfbe82238d2fb90eb42b743dcbe7b12b33f77e31ca85eaf694dcc1159c2fd4778fce93ceca25f5123aa63ad8ddbf776400d489d8d3d46665c9d22b4382",
            "85f5ab60296a8c7fa5219cfae92959c1bbc186f83c0d85d8f256a44112dba28333261d6c3e5eb31a874a9c481d807217d2855e916f350e47afb08ff2c4a0b7250d98000fb36e0fef84a2e99cc50cf1c5578fee983177e23ecaaa43c830113bb25dca7ac3c410aea87cd18f92e84d02ef5665d1b45649bb39b11a4bb894c9821504bcd47b84f9262bf367f1693898c31021c233b15473473e32f3978d76bc7b8dfda50ede2867f795c591fa28a45e7e64783f80367057c25bce74b409fc8ca797b01717b3510d3b028b5d47c4ef8564c97a1753e36c89ea92043bea752dadd9229b5d41148111d08771b42762c2781482a4df552daddff2d0d71aaafa9991956003288625c187531b42a88418c6c23bbf935a20aac43858f26ccbb1d862277da2d84e1076aa38f24f468e1d11bfa72a5d89d726a9e65c146a129766a4c14ea1ddd1d465f14a27c89f86b90c1fdedc0b776442504c08abed17fcebcb3243882b6a7df1ea534ccccd3f55fd693b9866ba167a2f1dab5863e0a1d8e87f8a85fccf70",
            NULL,
        },
        {
            4096,
            CRYPT_CTRL_SET_RSA_RSAES_PKCSV15,
            CRYPT_MD_SHA1,
            "a1e40cd0d2acefd97d50653dad7a3295c21fcb5a38e3ca375e4346ee280ba78560a2cf497abcd129d5065cd25de48dbb33870a381977b7891b54fed2c6212cb5dfc9b4ac2b4f65f625dc69e54a23ba4b3d9450de7d4b3c6dd6c1368ccb7c7bc4778a152362a7341a488a9f17958889999040c04a964b78e203e79eefbc2de6a97e618c351314351b898e2bef2bf37fbfc2a7fadf0125bae892e57c7fc27e2d6b2d24d0ec913f0e68cd03fb86e4e59364ba20f1d519d36ec3a350a4b450db899aafd182473348757423c8abf767e8e1aaa74283c9c3387ad925952fc2511b2b3ab54280bb1f94d9c41f2cdb6ae3428981294ed5d0827071b85136c8a850ce6286bb702f852f064af3f6675a2f18ec6c0ee6544d98ceaa748136f4042fecf718ddc9d8ac4abed0392a27fb5fc854038cfe5584ca3f99ae7016ecad1b9908d0512c908c81a15e1fb6789ba6b73de08984f6cd188a9846287a23ad92269bbe21bfad0f3616f963a0b64232112482d231257335b422517540cb50c7a7dbd12da95f0de823823c044f16ae72e05b2646f0c068b7f70c83a9d86468b3d6ff473e7da727ec707dc5b7f9d6e3603c0897c5b9ca3f0f04ae3250571bff180fdcf58f9d1d44138d5f2c840787922b1aa750896b19e5042961ea1dae3f28047d0053d9686995bc9e33590f64fe07fb60d9ee6268b943aae3a0bab266f0c633a773218c46f1ef",
            "03",
            "6bed5de08c734a90fe3598d3c8fc21b92c15323c25ed317a3ed7849ec55d1a58eb1734dba7288b7138aee88c3e985e7ccd04b17abba525061238a9e1d96b7323ea867872c78a43f96e92f14386c27c32290d8b3efe32284939d6245ddcfda7d84fb1636cec6f781185b1bf650e5b0666602b2adc64325096ad45149fd2c94470feebb2ce0cb82367b109729f72a2552a81c551ea00c3d1f061ee52ffd6fec8f21e188b4860d4b445de02a7af4343b7987c15f68e11379f2d178b187835e7b111ca8bac2f7785a3a2c285c7fa4545ebc71a2c57dbd77afc90c3b8ca818b6772272381ab276a633bd814c89247422c5bab70df3935ac4af67ae0cf307035deec58c2d17e582d327a2d1e3fae1228d2d1558822ef04e05d33861c47c9ca73443f94f9786bbe172070fcd5acf45017e67d40c307354589433cffe3264edfd2dc07d8973d397e5908606c76168ba9655c332bfd7b86ce2d785734a9ddd32834f93e56a02a5378040585663b0cf3846d602f38cdabc081fb02e2e3a137c6c386926ed9a24d05a41aaac6d10d61ce9c1f38a4c1c03f3f37da4c36b33550907ab131444c11c38298df12b6d8d89c2c2aaaf0280c1ec55d1ba4f8d4b50ca94d1da889f6f413cfc6943c3feae067cafcd554c03b1973d2ee9f53414b3703d15b6782218e01657d5b192c431374ab8f2441d84897b749c600c8004235d40094b9f2516bb8db",
            "54657374",
            "0a13b3abc2fb196212045827ce3e21d564b8959e7cf09783ce7b3f2dce9e4488359d9e647232b1280fcc8106392bf8bfc2daffc1f4d97002ed8b9dcc21768d29df342b8d02e0912af351e8267ad4ac9a11d84e8f238b6a389779157f7be3ebfc5b42dfff00539d302a86701b1f2d1f566b667723b219854f26a7da37b05a0362ce96f0aacdd3fa6d7186115df0ab0ba75afc2ae0f6688d6771d9be59e1d17fd45a5cd865485f7d818f253e22a3d4d93662f63238c1a92ab79446616e62bfa05c59c386fdc0ecec97aa5045517b8c6d0e4898237189f3aa61c21632dc93ff4c87d6201752842f1f0e2541bc3d11e8ed7dc25bb8dfc80e4bbd4f40e2728bce7909aa9cb19aea66e86b29c512b773f30399314d7929c26445812095a93eeb65382395c8a14a13f3fb73a64ae7afbe2c7dfac79ae2a40b1789a48daaebea1c0d39a32ff411d199c2532b4512ad3ba67fb7a02b8f5e762bf7d1b3b9207234306b230ea5c9640cb2d034c1ff24edefc98e1c4df8f7821a2a0d718bbe44b9d0896fd346b3bb9b0be69d95005b27153ba1f1609c2426822f80975fd342900648f7d53dc82bc1bc9bf247a4bbc8a84ca253a9204d286ecaf33bf67d06934a9f63ccdaa6142d6932854185a844d68cad7cc9852aaa5bd26c7762b7e4e978b2e09d567f196942b133c45b6d14c3227f5646cf6657bdbc85fc684fcfcd2963bdac98f4713349",
            NULL,
        },
        {
            1024,
            CRYPT_CTRL_SET_RSA_PADDING,
            CRYPT_MD_SHA1,
            "a155094c9c89e3eea1e62672047f8b1a1e8ca78919c5bcb0cef0b8e8e40c07197031ede10304541c766fd5da29faaf4a924ea27483d65fc47c24385fb010a9976bd346f0702a250fede9211b69bcb95516b31bacd0a9368376653a70bcf0b507869b08e8af1c1ce5eff28d02b6b6591c4fb52f520bbaaea773a4892a7ba2f713",
            "03",
            "6b8e0633130697f46beec44c02ffb21169b31a5b6683d32089f5d09b42b2af664acbf3eb57583812f99fe3e6c6a71f870c346c4dad39952da8182595200b1bb938de5cfbc817a443b2410bc859396196cabde8f5734b38bf073c8d31fdf4e4071610ef1b1559aef498f2418c82c13d49150d805db08bac92ab0467154765f4eb",
            "0fe6fcde58648f13ebd5f0ccbd68458da8ae18dfbe82238d2fb90eb42b743dcbe7b12b33f77e31ca85eaf694dcc1159c2fd4778fce93ceca25f5123aa63ad8ddbf776400d489d8d3d46665c9d22b43820fe6fcde58648f13ebd5f0ccbd68458da8ae18dfbe82238d2fb90eb42b743dcbe7b12b33f77e31ca85eaf694dcc1159c",
            "2b5d2d5e1a4d4d97243bef743e5a7990ee6171bcfa37733968fd20b317e27af663f99a948f70446b28248e1b2e55a4924a1dea99845473a9c2a1ec4534ae796ee4caeb4ccaa99072bffd84e2757b01e82f1a8bc602997fa0a0cfa4249016a20176a79b4e07b163ba86298782b7ac868f64b33d1ac3cf5d18848c4d59d94b4bec",
            NULL,
        },
        {
            2048,
            CRYPT_CTRL_SET_RSA_PADDING,
            CRYPT_MD_SHA1,
            "d419435dfe85ccc42a3e29493d5cd742ec38b4bfa20438b47d4907d8e919990642f2f1125ba51275391358a09e8af812018ca120f5141c39ef4278dbac00c3fb043b4c046f823caf4fbe0dcf534d6fe32e38f347f9b2cefa8e104ab5f8da69d398040d282521386bdadfcecff23ae506abd459304db608ae29abf857fbbcceafcd2cdedc01154da12dc89f66a5439269fb8e79140fe720c0ba84448e1e51d90558e2e141859079e422f634d8a18960c830daba1f442b050c0a968fff1e5086306b56146cb8552f540cabdd7429e0689fc4a5bafca18918d05351082ea1cd20f587f7009e1cccc1cc4c5f2e653601094987ff1263534a11a83f80961b2620affd",
            "03",
            "8d662ce95459332d717ec630d3933a2c9d7b232a6c02d0785386053b461110aed74ca0b6e7c361a37b623b15bf07500c01086b6b4e0d68269f81a5e7c80082a758278802f5017dca35295e8a3788f5421ed0a22ffbcc89fc5eb58723fb3c468d1002b37018c0d047e73fdf354c274359c7e2e62033ceb0741bc7fae5527ddf1ea66e1a0e18427e51310a8d50874e10dd029e0883e0b4cc9ab23ac4b359f3771b10e8b8da0ce7b55df1be6a6a93cb38cf7c27f18d06d053892bed87c5d0a32ca14430028a5913ce16ab3ada23514f23a3374cce8182d38ee22b72a8ebd643e4163af457b06ebf1764929b799895d7064301b48ff3f2f2dc56c5318ae7b132116b",
            "0fe6fcde58648f13ebd5f0ccbd68458da8ae18dfbe82238d2fb90eb42b743dcbe7b12b33f77e31ca85eaf694dcc1159c2fd4778fce93ceca25f5123aa63ad8ddbf776400d489d8d3d46665c9d22b43820fe6fcde58648f13ebd5f0ccbd68458da8ae18dfbe82238d2fb90eb42b743dcbe7b12b33f77e31ca85eaf694dcc1159c2fd4778fce93ceca25f5123aa63ad8ddbf776400d489d8d3d46665c9d22b43820fe6fcde58648f13ebd5f0ccbd68458da8ae18dfbe82238d2fb90eb42b743dcbe7b12b33f77e31ca85eaf694dcc1159c2fd4778fce93ceca25f5123aa63ad8ddbf776400d489d8d3d46665c9d22b43820fe6fcde58648f13ebd5f0ccbd68458d",
            "26f7795d5cbfa6730a539248b96b4434b228fa6fcc598ef5b29df70263a5b01cb937c5a0b92450b3fe119faa9d957243f380a4fd088c9082324da21f7e3eed1d8a71f4ee111bc5367cc23197d43ed07e3c34b64cd25df950dbae9f463c9954afc08b97a8302072b02adf466c7391de6ab140175e812041796266dcbb86879fbd0208a06d548abaf3ffcf13eeb9586de2f2739f47b6fa913a397c3a5eccd2142f1354cda31278ff12aef3d43425eea3d4dbd6d5c785d3109003c560944b39e30316d825bd9f303f754accf6dc3c128916e858095e6bcf110d422cbcb9e73f2fab02872003264bebbe93aacf897a80fae4190a5541e846678b9a7a612a13daf00f",
            NULL,
        },
        {
            3072,
            CRYPT_CTRL_SET_RSA_PADDING,
            CRYPT_MD_SHA1,
            "d4766ee8d58ee9ae2cbde18bd6a89671118196ef711c4dd8e41926cea76628443e99a70d46e8b0ac68e140b329ded9fb68a2985f054e5d42d1d3a053c1a4de3d65223b9f1befae60af9a0c9879b9717f83d83aa53192df2b30477a706253f20ca345ad28fa9c3f0a09990e8f5f6aa7e000fd4e08e4d6b934a10b0e38d4cc78742c4dc6c74277fdd9e82a73074f8c9bb52b0b22781904ac748851552bbd25cddc498a3ce3182992b31cc065966f6a64069fa37c89cf5e2142f98fa6fd307db44cdbead66e575a74fe1d42aee98306381fb18d178a9e716a8dc20ff271a2253b4e0336bd870f4780dabdcf7dfe0aacc1415f00aa7d9f7ebb85ec28cb11e537821c1fdd44c62cf5ebe0fcc95f8c82a5309d5bb4cfb488648148678dc68630a4f9f8de298206c21415bb58e29869423f4ee1737458b0f5f30cb9833da7e43e7e768e0ded4c067151060ceae29c0913c87ee705a5423991a5ad6b308834425e0659cbc18bfe762f310db3c822bca37671a60c5262a6e93b0b0bfad5e2c7c5e73e0c91",
            "03",
            "8da449f08e5f46741dd3ebb28f1b0ef60babb9f4f612de909810c489c4eec582d4666f5e2f45cb1d9b40d5ccc694915245c1baea03899381e137c037d66de97e436c27bf67f51eeb1fbc0865a67ba0ffad3ad1c37661ea1ccada51a0418d4c086cd91e1b51bd7f5c066609b4ea471a9555fe3405ede47b786b5cb425e332faf81d892f2f81a553e69ac6f75a350867ce1cb216fabb5872f85ae0e3727e1933e83106d342101bb722132aee644a46ed59bfc253068a3ec0d7510a6f5375a922dcb0dd1e42266de1a8813fb9cca593eed3dcbb7a2ac0fbf7861cb556307ef66e5b0efa178e4ea78b4112424d68e899f1d35bfae3c76f0d3434ffa4b374b97a5077e6cf77b00ea403ceb2eb1ad6d7cd90b460213a5cd5fcb3f597e9651cfef83f3db3b4df7521be95564b1c4a4acd855c024a635ec2fbb27ed1a88d1b855ff94171016d5222f5ccc351bfc5ad602d8929a16977422e9a87973e5ffcdfa2d72b1a0a661de1e30ee7b79c0e79402a4276bc71ad515d76f6be2ca141a7f02c6483fe4b",
            "0fe6fcde58648f13ebd5f0ccbd68458da8ae18dfbe82238d2fb90eb42b743dcbe7b12b33f77e31ca85eaf694dcc1159c2fd4778fce93ceca25f5123aa63ad8ddbf776400d489d8d3d46665c9d22b43820fe6fcde58648f13ebd5f0ccbd68458da8ae18dfbe82238d2fb90eb42b743dcbe7b12b33f77e31ca85eaf694dcc1159c2fd4778fce93ceca25f5123aa63ad8ddbf776400d489d8d3d46665c9d22b43820fe6fcde58648f13ebd5f0ccbd68458da8ae18dfbe82238d2fb90eb42b743dcbe7b12b33f77e31ca85eaf694dcc1159c2fd4778fce93ceca25f5123aa63ad8ddbf776400d489d8d3d46665c9d22b43820fe6fcde58648f13ebd5f0ccbd68458da8ae18dfbe82238d2fb90eb42b743dcbe7b12b33f77e31ca85eaf694dcc1159c2fd4778fce93ceca25f5123aa63ad8ddbf776400d489d8d3d46665c9d22b43820fe6fcde58648f13ebd5f0ccbd68458da8ae18dfbe82238d2fb90eb42b743dcbe7b12b33f77e31ca85eaf694dcc1159c2fd4778fce93ceca25f5123aa63ad8dd",
            "5a53aed8b330fb508fc2c9319f28a1b38195f8b13501466f0d707fd41d180b3257a6cf0e32db9450a41eddcbe4a865bd3a94a8659bdf7b12a2b2f134689d557c5ce368f23c483086233d3231a0027b0b5108eef4fcf9e93aa5e7fc1aebc2335be72ea9b133be8763f217b1cfe9e46af5c9fa2db4eae26e10a9eca957ba63ccfe8ea3e955ffc0b4874c0637cc0285479d5c03ad0d1505df4f215bac6183eddbea364b7f904ffea5d99c279ce38cfddc96b9ef54802bc5914749a9571b9fd4d77c758d772df5e1a014f6fa3ed81058a9be03c7336ad5be0cfdcc8aae58689e6faf3250e504a298a2ea548d0b57247fbf022600c6a76aca53d60ea12c22487581eaa83a3e8451fcbbb45651f1b0bdb9d4629198844c2463ac1dcdc6c5d4029b4b14f05142f2aa9ba4e61d990ab057ff7a42efa02322d0e2a217fecaafee0f128ba5c6f17713d3962023c781ed41610a4f4a5fad3b2a431480b216002e7422f85943e75008e36a815a83a41f8e5395c51ea5412860f25ddcf49dbce064ada1bd7abf",
            NULL,
        },
        {
            4096,
            CRYPT_CTRL_SET_RSA_PADDING,
            CRYPT_MD_SHA1,
            "bf5fedf7045645cdf840431fe82fbd363f4d06ae41b617446d4d064df4da7f6515465cbf51bead40fc651c2df578c2974d04bc54f4cd9a89aadb65ec574e327a40dc3896167aa2573c3ff20e44fb8f92a7258fa3ad0c4f17cc787a08940862992407cd87d7215e1743c0a505757d0460431040bc2f6702f59877635bfdf6b3d96630b4e52fea09b6f9b943bea6729271edaa62b9d4096d32bb273cbd7f85a74e43a52120cd12d2c5a44929085b828db57e548141b6b1452ffcbc627ff953f5062e66c534b6151be574ca682255e57a628c10fc838229bdd34657343be49c52a80fa353ae17766f4277550b73457391c5173e1d8ff54431f0b8203a722c89a995a53380c3c3ff69bb7e0a9a2026d4bde193c285dd2885b9c864e372dc8cf2fd2fa46e0e46be226c7a5000a0a67d183b395bf539023918dadf2b9867a6cc4d222d0f5a47c67f5a41984ba2baa3e52440c1d71819e874f2d30f980d6f1578faf4714fc9ffab27935cba7a2693d958f78172112059cf8249289a49aba93ee668520271048786a0e96ec9089bd718f87ec8580415862b71a6c41d51f5fab936404fc37e386ca522e918e3889184bc5556a79cc41921fd30e6daab54ea9486b400e1c1b7eb7494e11df63508d828c1c011c1ca0fce9582e9df926a102eb024db943ff69fecc6d946aa206947c8dc3479c68536d91b7eca8bfbd6e3599d50e133fb7a27",
            "03",
            "7f95494f583983dea5802cbff01fd3797f88af1ed67964d848de0433f891aa4363843dd4e129c8d5fd98bd73f8fb2c64de032838a333bc5bc73cee9d8f8976fc2b3d7b0eb9a716e4d2d54c0983525fb71a190a6d1e0834ba8850515b0d5aec66180533afe4c0e964d7d5c358f8fe02ead7602b281f9a01f9104f9792a94f2290eecb23437546b124a67b827f19a1b6f69e7197268d5b9e21d21a287e5503c4ded7c36b6b3361e1d91830c60592570923a98dab8124762e1ffdd2ec5550e2a35974448378796367ee4ddc456c3943a6ec5d60a857ac1bd3e22ee4cd7d4312e1c55fc237c964f99f81a4e35cf783a2612e0f7ebe5ff8d8214b256ad1a17306710d4702ea647a7fe38a38992874c6474ebd59a0a72e21f52057a87f7f8e830ec4bf5a0c7a0b0b5ae070efb8c615a345bb3a86f75ef37c86608512a75a5214fa3da6f8affae6f251fbd4bd4e5e10703c61b11bdedcfdc5deb8488a25d275f84b359ae87490e60f12b32a117e670cfc080312a17f915d33d2d63a08921a6d2533f2d99160e6c73d0f263e02e7cc29d1cad41f9282a2c8846e848221d542ab921ecdc9165a3053619836f68e0859c7990a3cd3a39bb41cfcb283cbc44bcfa52b9b5f80b400efa1ffb72a82e1572b75b31bc39ecfbc75def6c5412879c7611ede35fb2258e8fcace8ade2bb3ed94258ac0d3e1ab01ee224a2c054ad8820bacccc9a810b",
            "0fe6fcde58648f13ebd5f0ccbd68458da8ae18dfbe82238d2fb90eb42b743dcbe7b12b33f77e31ca85eaf694dcc1159c2fd4778fce93ceca25f5123aa63ad8ddbf776400d489d8d3d46665c9d22b43820fe6fcde58648f13ebd5f0ccbd68458da8ae18dfbe82238d2fb90eb42b743dcbe7b12b33f77e31ca85eaf694dcc1159c2fd4778fce93ceca25f5123aa63ad8ddbf776400d489d8d3d46665c9d22b43820fe6fcde58648f13ebd5f0ccbd68458da8ae18dfbe82238d2fb90eb42b743dcbe7b12b33f77e31ca85eaf694dcc1159c2fd4778fce93ceca25f5123aa63ad8ddbf776400d489d8d3d46665c9d22b43820fe6fcde58648f13ebd5f0ccbd68458da8ae18dfbe82238d2fb90eb42b743dcbe7b12b33f77e31ca85eaf694dcc1159c2fd4778fce93ceca25f5123aa63ad8ddbf776400d489d8d3d46665c9d22b43820fe6fcde58648f13ebd5f0ccbd68458da8ae18dfbe82238d2fb90eb42b743dcbe7b12b33f77e31ca85eaf694dcc1159c2fd4778fce93ceca25f5123aa63ad8ddbf776400d489d8d3d46665c9d22b43820fe6fcde58648f13ebd5f0ccbd68458da8ae18dfbe82238d2fb90eb42b743dcbe7b12b33f77e31ca85eaf694dcc1159c2fd4778fce93ceca25f5123aa63ad8ddbf776400d489d8d3d46665c9d22b43820fe6fcde58648f13ebd5f0ccbd68458da8ae18dfbe82238d2fb90eb42b743dcb",
            "b55436b2fe34b7f916f76fe4fb1215e7b613396181813db212cb298ae095cd97198992b3b5de6022b7921757868946faed061ce8b2ee3435a604099960e23eb2ece44c25e1a42c870337b7c8937e3e3ed737b992984f6d7aca9b2427c38d883af79b66eb23be510aef3d0df055dde54d62651b7a8712b7832abd6b4f002710af39fe0cb21722a16f227b7368d0379d6acdfd7fb8615fd36b156c00601d3b03c1192d8fbd5724234a0b06862244f6b840fcc99e1675d658cf139356c0f103552f96140e2239db379f23045f4cf626efab84a6402ff5633e549b0c2163173517141233c74529befd3106dbdb390064480bd507efd136f2eb8347e36ddf0d81dd135029402b137959aaf7d656054c86394384df30dcc3c83c0d697a50d596575389fe207f26e27f683ef8143106af35298c8411a586cb02c64efd30b674e628c402fcb747e71a2d99eb0772ecb478bdfee8924f33989f06263eb8f13297a7031c539e98f9119ddd78eb6167e91e04f1c5f2ed12639cb2c17ffe4c561b21fefe7e8da7b6642623e8e11f1ef77d3422d406ed91dc6d23288a4330b3e23ca46ddb094567c23a20c0d853ed06f1a8eb8f91560bea42ee0d5ec9a8b8f7f39a6a7433bb77e5791b0ed4558ff3dc9ce686901ef90cd75d2d2c3e04881820de6b35797e31cb5a20abc0e57e2fb2bb63d2afd89162cc4bdc0c1aae1be5b49f6dd58c9953fd8b",
            NULL,
        },
        {
            2048,
            CRYPT_CTRL_SET_RSA_RSAES_PKCSV15,
            CRYPT_MD_SHA256,
            "cdf0b791aff9d4862b5baa15739ddc99e161b638207d103c903096c67fb4e6317d37020034f128cdff1e9a74aef4cf524435802e6e411c52c3883f3c2dc39f961affd27a2b420c1205a7178f9a69b74bc2990919ac618b8e8f0f48ec001c0773c751322d920ac1a003992c59222220a8485d08c8b201fb2211be060eb65437e478e242822fe315609257cacea87f1d635c13ae7cbe4455c72408d70f7f4132c8c7f45daec6de3a01529d29c49d5a5287f42c165fbb5b1ad59c3d5ae49384a97b0f74d16603450e706416fc9fb1bc6c2e050eda48cde67ac74c78c51195cc4d119e8c70de0dbef59180f7b98ee9f11c86014ac6ea2edc2792bb63456e67e867df",
            "010001",
            "39d6285fd089bbdf806eca6a22e1cb522623807eebd4e3c9f67ec6e1717d3706e011224d379120f2157b9d4a36d687212609d67973ba727f65edae40b2e3953e9d4f8a67881d90f140c8280c4b03f497e0cb84ec4266d4c0513a2c332766b7cb12c7a16d7dedea6a0b88a99550ca3fdcb311f9c50f8511e8040e9779eb47e4b812a5ea2f274fb68a82443c91582ad9b98d05e36f48533410f04b64ba4c6bf6f90ed62806a506afcf45646770744ace5952ecad86a89afd526a50377678381414e2e4d7610c7def7fcb926cf26371bd63457c45d7bb30bd31ce0a62787a4fe00d65d8f73c6cec4476a50a79a16f6204e3e193e55a7871b832b40b705a08ba37e1",
            "4a4e743f877ea6e94e545a56ccb5a1f99efc7eb1e8191929152a56d41dc924254a4e743f877ea6e94e545a56ccb5a1f99efc7eb1e8191929152a56d41dc92425",
            "842ceabd0c227b5adb1e41961a3a3cfbcf371273c7e3ba63d59fe1031c9555a0cec446f6de4c1265b979369b5893608d9d6479cc9ff3c45e6ec3fc66c5bdd6e2886dc01d3039b899a2b23a3c877bd3d7dd7447f123f20644adf0b69c8834540f1d995547f37fee2053c2287119d572047697ecadf92d774922b6f449f007d94692a6438ea0d27f5611f360e094e220cbdbf3370fa026ebded8e653f7a368b7bd67103a2cfb3d97467de7f3b040c2968ed9ea1ce4f00b9a968eefce9b78d7cb01388f447f646be19bd2dc54acb069602b9630c7f058d1a4be711109e50cde91b295fbf92da42b8ce43bd2f0676ac6c61a6981feaed8b6cccbe9f35db5c3cf61a4",
            NULL,
        },
        {
            2048,
            CRYPT_CTRL_SET_RSA_RSAES_PKCSV15,
            CRYPT_MD_SHA512,
            "cdf0b791aff9d4862b5baa15739ddc99e161b638207d103c903096c67fb4e6317d37020034f128cdff1e9a74aef4cf524435802e6e411c52c3883f3c2dc39f961affd27a2b420c1205a7178f9a69b74bc2990919ac618b8e8f0f48ec001c0773c751322d920ac1a003992c59222220a8485d08c8b201fb2211be060eb65437e478e242822fe315609257cacea87f1d635c13ae7cbe4455c72408d70f7f4132c8c7f45daec6de3a01529d29c49d5a5287f42c165fbb5b1ad59c3d5ae49384a97b0f74d16603450e706416fc9fb1bc6c2e050eda48cde67ac74c78c51195cc4d119e8c70de0dbef59180f7b98ee9f11c86014ac6ea2edc2792bb63456e67e867df",
            "010001",
            "39d6285fd089bbdf806eca6a22e1cb522623807eebd4e3c9f67ec6e1717d3706e011224d379120f2157b9d4a36d687212609d67973ba727f65edae40b2e3953e9d4f8a67881d90f140c8280c4b03f497e0cb84ec4266d4c0513a2c332766b7cb12c7a16d7dedea6a0b88a99550ca3fdcb311f9c50f8511e8040e9779eb47e4b812a5ea2f274fb68a82443c91582ad9b98d05e36f48533410f04b64ba4c6bf6f90ed62806a506afcf45646770744ace5952ecad86a89afd526a50377678381414e2e4d7610c7def7fcb926cf26371bd63457c45d7bb30bd31ce0a62787a4fe00d65d8f73c6cec4476a50a79a16f6204e3e193e55a7871b832b40b705a08ba37e1",
            "4a4e743f877ea6e94e545a56ccb5a1f99efc7eb1e8191929152a56d41dc924254a4e743f877ea6e94e545a56ccb5a1f99efc7eb1e8191929152a56d41dc92425",
            "a81653d15cb23545902169d98c6281b9cf2b90a09e32c8fd12d7bc70c664820dcb29daf280de5c9257d52e30094dbb446469e07b2f0b290e63dd2a9778aea203968c9ac22b5511c077b136651dd43d986ac03e2cc87b3cbb37e21abcf4e980a23e60bddab0b88e68e5b1bcdabbd9c1a2a5ad639664f4d1b1280c5f98187a1ee72ece18453612e2762271d1a392ea16556c1383d01f8d6c118b76b416325f6903061d0a2dc0952a0af8016c52734cb8091cd3490a72ad8742e55517ee92efaf751dd14f8a70bcc273ef749c9838082ab1c71da49429c28378408be759ee4ec5acfd416cc31393931c565822046f7dc0751aa189ff12557f0750fef6c3261616b1",
            NULL,
        },
};

static void SDV_KAE_RSA_CRYPT_FUNC_TC001(void **state)
{
    RSA_Enc_Test *test = (RSA_Enc_Test *)*state;

    int32_t keyLen = test->keyLen;
    int32_t padMode = test->padMode;
    int32_t hashId = test->hashId;

    Hex *n = NewHex();
    Hex *e = NewHex();
    Hex *d = NewHex();
    Hex *plaintext = NewHex();
    Hex *ciphertext = NewHex();

    assert_int_equal(ConvertHex(test->n, n), 0);
    assert_int_equal(ConvertHex(test->d, d), 0);
    assert_int_equal(ConvertHex(test->e, e), 0);
    assert_int_equal(ConvertHex(test->plaintext, plaintext), 0);
    assert_int_equal(ConvertHex(test->ciphertext, ciphertext), 0);

    int paraSize;
    void *paraPtr;
    CRYPT_EAL_PkeyPrv prvkey = {0};
    CRYPT_EAL_PkeyPub pubkey = {0};
    BSL_Param oaepParam[3] = {{CRYPT_PARAM_RSA_MD_ID, BSL_PARAM_TYPE_INT32, &hashId, sizeof(hashId), 0},
                              {CRYPT_PARAM_RSA_MGF1_ID, BSL_PARAM_TYPE_INT32, &hashId, sizeof(hashId), 0},
                              BSL_PARAM_END};
    int32_t pkcsv15 = hashId;
    uint8_t pt[MAX_CIPHERTEXT_LEN] = {0};
    uint32_t ptLen = MAX_CIPHERTEXT_LEN;
    uint8_t ct[MAX_CIPHERTEXT_LEN] = {0};
    uint32_t ctLen = MAX_CIPHERTEXT_LEN;
    int32_t noPad = CRYPT_RSA_NO_PAD;

    SetRsaPrvKey(&prvkey, n->x, n->len, d->x, d->len);
    SetRsaPubKey(&pubkey, n->x, n->len, e->x, e->len);
    if (padMode == CRYPT_CTRL_SET_RSA_RSAES_OAEP) {
        paraSize = 0;
        paraPtr = oaepParam;
    } else if (padMode == CRYPT_CTRL_SET_RSA_RSAES_PKCSV15) {
        paraSize = sizeof(pkcsv15);
        paraPtr = &pkcsv15;
    } else if (padMode == CRYPT_CTRL_SET_RSA_PADDING) {
        paraSize = sizeof(noPad);
        paraPtr = &noPad;
    }

    assert_int_equal(ciphertext->len, KEYLEN_IN_BYTES((uint32_t)keyLen));

    CRYPT_EAL_LibCtx *libctx = CreateLoadLibCtx();
    CRYPT_EAL_PkeyCtx *pkey = CRYPT_EAL_ProviderPkeyNewCtx(
        libctx, CRYPT_PKEY_RSA, CRYPT_EAL_PKEY_KEYMGMT_OPERATE + CRYPT_EAL_PKEY_CIPHER_OPERATE, "provider=kaev1");
    assert_non_null(pkey);

    if (padMode != CRYPT_CTRL_SET_RSA_PADDING) {
        assert_int_equal(RandInit(), CRYPT_SUCCESS);
    }

    /* HiTLS private key decrypts the data. */
    assert_int_equal(CRYPT_EAL_PkeySetPrv(pkey, &prvkey), CRYPT_SUCCESS);
    assert_int_equal(CRYPT_EAL_PkeyCtrl(pkey, padMode, paraPtr, paraSize), CRYPT_SUCCESS);
    assert_int_equal(CRYPT_EAL_PkeyDecrypt(pkey, ciphertext->x, ciphertext->len, pt, &ptLen), CRYPT_SUCCESS);
    assert_int_equal(ptLen, plaintext->len);
    assert_int_equal(memcmp(pt, plaintext->x, ptLen), 0);

    /* HiTLS public key encrypt */
    assert_int_equal(CRYPT_EAL_PkeySetPub(pkey, &pubkey), CRYPT_SUCCESS);
    assert_int_equal(CRYPT_EAL_PkeyCtrl(pkey, padMode, paraPtr, paraSize), CRYPT_SUCCESS);
    assert_int_equal(CRYPT_EAL_PkeyEncrypt(pkey, plaintext->x, plaintext->len, ct, &ctLen), CRYPT_SUCCESS);
    assert_int_equal(ctLen, ciphertext->len);

    /* HiTLS private key decrypt */
    assert_int_equal(CRYPT_EAL_PkeyDecrypt(pkey, ct, ctLen, pt, &ptLen), CRYPT_SUCCESS);
    assert_int_equal(ptLen, plaintext->len);
    assert_int_equal(memcmp(pt, plaintext->x, ptLen), 0);

    FreeHex(n);
    FreeHex(e);
    FreeHex(d);
    FreeHex(plaintext);
    FreeHex(ciphertext);

    CRYPT_EAL_RandDeinit();
    CRYPT_EAL_PkeyFreeCtx(pkey);
    CRYPT_EAL_LibCtxFree(libctx);
}

static RSA_Enc_Test SDV_KAE_RSA_CRYPT_FUNC_TC002_VEC[] = {
    {
        4096,
        CRYPT_CTRL_SET_RSA_RSAES_OAEP,
        CRYPT_MD_SHA1,
        "a911245a2cfb33d8ee375df9439f74e669c03a8d9acad25bd27acf3cd8bea7eb9dbe470155c7c72782c94861f7b573cd325639fb070e9ba6e621991aefa45106182e4d264be7068035595d7549052989b3e7fd04cabc94012c1278a0ef8672b1a51dd1a9e276816ba497dea24b4febe3dd8e977707bcd230ca6fb6f8a8bff9e6ba24fbadcd93f00126b19b396a38e6ef86d18fef945b9154c1963fb488c7025953511f86d05638bfe056493730bc6778446e59cd3c5c3acf07a0a3a64943793652f10e3292aa7a6d25a03181cc6f6ba0658d909e59ce2a02bacc9766fd8c4fbd4ed9c23a866844b8a794d49e505f9f944870a71aadbe5338039825c2dff81af3",
        "010001",
        "290d117f97d672f3647c2b24402832b153d22a25820567688645ed95ffa6e38d116347486ab4b485c27aef4962653bb60257ef82256785a1d3d52aa0e0b94c37279dee7bb308688aaee98108de6f1373ed2c12429c9b8770756c12c03908b346b129f963bfaa38a8937190cc656f057ef1a812dd0312f51285c4f46f9241f3028ea6a61db0e9255976469f5d5542ced55ee2d6f4afe766c0a70f49871d369dd8f3a82a7141639efd4a1f4a4009821c3c2b9f5c5f5eef99a5f00fbd8bc8191a3654e8f8d8ce12d90e5ff2a4c530b76306c8c56e0549a6f277ab2af3a60cccbf4bb4b2cb47f04f211f8b86aa653bf6913f3b5ed190c51b5958e40597a2dfd30061",
        "01020304",
        NULL,
        NULL,
    },
};

static void SDV_KAE_RSA_CRYPT_FUNC_TC002(void **state)
{
    RSA_Enc_Test *test = (RSA_Enc_Test *)*state;

    Hex *n = NewHex();
    Hex *e = NewHex();
    Hex *d = NewHex();
    Hex *plaintext = NewHex();

    assert_int_equal(ConvertHex(test->n, n), 0);
    assert_int_equal(ConvertHex(test->d, d), 0);
    assert_int_equal(ConvertHex(test->e, e), 0);
    assert_int_equal(ConvertHex(test->plaintext, plaintext), 0);

    uint8_t ct[MAX_CIPHERTEXT_LEN] = {0};
    uint8_t pt[MAX_CIPHERTEXT_LEN] = {0};
    uint32_t msgLen = MAX_CIPHERTEXT_LEN;
    CRYPT_EAL_PkeyPrv prvkey = {0};
    CRYPT_EAL_PkeyPub pubkey = {0};
    int32_t hashId = CRYPT_MD_SHA1;
    BSL_Param oaepParam[3] = {{CRYPT_PARAM_RSA_MD_ID, BSL_PARAM_TYPE_INT32, &hashId, sizeof(hashId), 0},
                              {CRYPT_PARAM_RSA_MGF1_ID, BSL_PARAM_TYPE_INT32, &hashId, sizeof(hashId), 0},
                              BSL_PARAM_END};
    int32_t pkcsv15 = CRYPT_MD_SHA1;

    SetRsaPrvKey(&prvkey, n->x, n->len, d->x, d->len);
    SetRsaPubKey(&pubkey, n->x, n->len, e->x, e->len);

    CRYPT_EAL_LibCtx *libctx = CreateLoadLibCtx();
    CRYPT_EAL_PkeyCtx *pkey = CRYPT_EAL_ProviderPkeyNewCtx(
        libctx, CRYPT_PKEY_RSA, CRYPT_EAL_PKEY_KEYMGMT_OPERATE + CRYPT_EAL_PKEY_CIPHER_OPERATE, "provider=kaev1");
    assert_non_null(pkey);

    assert_int_equal(RandInit(), CRYPT_SUCCESS);

    /* HiTLS public key encrypt: OAEP */
    assert_int_equal(CRYPT_EAL_PkeySetPub(pkey, &pubkey), CRYPT_SUCCESS);
    assert_int_equal(CRYPT_EAL_PkeyCtrl(pkey, CRYPT_CTRL_SET_RSA_RSAES_OAEP, oaepParam, 0), CRYPT_SUCCESS);
    assert_int_equal(CRYPT_EAL_PkeyEncrypt(pkey, plaintext->x, plaintext->len, ct, &msgLen), CRYPT_SUCCESS);

    /* HiTLS private key encrypt: PKCSV15 */
    assert_int_equal(CRYPT_EAL_PkeySetPrv(pkey, &prvkey), CRYPT_SUCCESS);
    assert_int_equal(CRYPT_EAL_PkeyCtrl(pkey, CRYPT_CTRL_SET_RSA_RSAES_PKCSV15, &pkcsv15, sizeof(pkcsv15)),
                     CRYPT_SUCCESS);
    assert_int_equal(CRYPT_EAL_PkeyDecrypt(pkey, ct, msgLen, pt, &msgLen), CRYPT_RSA_NOR_VERIFY_FAIL);

    /* HiTLS private key encrypt: OAEP */
    assert_int_equal(CRYPT_EAL_PkeyCtrl(pkey, CRYPT_CTRL_SET_RSA_RSAES_OAEP, oaepParam, 0), CRYPT_SUCCESS);
    assert_int_equal(CRYPT_EAL_PkeyDecrypt(pkey, ct, msgLen, pt, &msgLen), CRYPT_SUCCESS);
    assert_int_equal(msgLen, plaintext->len);
    assert_int_equal(memcmp(pt, plaintext->x, msgLen), 0);

    FreeHex(n);
    FreeHex(e);
    FreeHex(d);
    FreeHex(plaintext);

    CRYPT_EAL_RandDeinit();
    CRYPT_EAL_PkeyFreeCtx(pkey);
    CRYPT_EAL_LibCtxFree(libctx);
}

static RSA_Enc_Test SDV_KAE_RSA_CRYPT_FUNC_TC003_VEC[] = {
    {4096, CRYPT_CTRL_SET_RSA_RSAES_OAEP, CRYPT_MD_SHA1,
     "a911245a2cfb33d8ee375df9439f74e669c03a8d9acad25bd27acf3cd8bea7eb9dbe470155c7c72782c94861f7b573cd325639fb070e9ba6e621991aefa45106182e4d264be7068035595d7549052989b3e7fd04cabc94012c1278a0ef8672b1a51dd1a9e276816ba497dea24b4febe3dd8e977707bcd230ca6fb6f8a8bff9e6ba24fbadcd93f00126b19b396a38e6ef86d18fef945b9154c1963fb488c7025953511f86d05638bfe056493730bc6778446e59cd3c5c3acf07a0a3a64943793652f10e3292aa7a6d25a03181cc6f6ba0658d909e59ce2a02bacc9766fd8c4fbd4ed9c23a866844b8a794d49e505f9f944870a71aadbe5338039825c2dff81af3",
     "010001",
     "290d117f97d672f3647c2b24402832b153d22a25820567688645ed95ffa6e38d116347486ab4b485c27aef4962653bb60257ef82256785a1d3d52aa0e0b94c37279dee7bb308688aaee98108de6f1373ed2c12429c9b8770756c12c03908b346b129f963bfaa38a8937190cc656f057ef1a812dd0312f51285c4f46f9241f3028ea6a61db0e9255976469f5d5542ced55ee2d6f4afe766c0a70f49871d369dd8f3a82a7141639efd4a1f4a4009821c3c2b9f5c5f5eef99a5f00fbd8bc8191a3654e8f8d8ce12d90e5ff2a4c530b76306c8c56e0549a6f277ab2af3a60cccbf4bb4b2cb47f04f211f8b86aa653bf6913f3b5ed190c51b5958e40597a2dfd30061",
     "01020304", NULL, "0102030405"},
};

static void SDV_KAE_RSA_CRYPT_FUNC_TC003(void **state)
{
    RSA_Enc_Test *test = (RSA_Enc_Test *)*state;

    Hex *n = NewHex();
    Hex *e = NewHex();
    Hex *d = NewHex();
    Hex *plaintext = NewHex();
    Hex *label = NewHex();

    assert_int_equal(ConvertHex(test->n, n), 0);
    assert_int_equal(ConvertHex(test->d, d), 0);
    assert_int_equal(ConvertHex(test->e, e), 0);
    assert_int_equal(ConvertHex(test->plaintext, plaintext), 0);
    assert_int_equal(ConvertHex(test->label, label), 0);

    uint8_t ct[MAX_CIPHERTEXT_LEN] = {0};
    uint8_t pt[MAX_CIPHERTEXT_LEN] = {0};
    uint32_t msgLen = MAX_CIPHERTEXT_LEN;

    CRYPT_EAL_PkeyPrv prvkey = {0};
    CRYPT_EAL_PkeyPub pubkey = {0};
    int32_t hashId = CRYPT_MD_SHA256;
    BSL_Param oaepParam[3] = {{CRYPT_PARAM_RSA_MD_ID, BSL_PARAM_TYPE_INT32, &hashId, sizeof(hashId), 0},
                              {CRYPT_PARAM_RSA_MGF1_ID, BSL_PARAM_TYPE_INT32, &hashId, sizeof(hashId), 0},
                              BSL_PARAM_END};
    SetRsaPubKey(&pubkey, n->x, n->len, e->x, e->len);
    SetRsaPrvKey(&prvkey, n->x, n->len, d->x, d->len);

    CRYPT_EAL_LibCtx *libctx = CreateLoadLibCtx();
    CRYPT_EAL_PkeyCtx *pkey = CRYPT_EAL_ProviderPkeyNewCtx(
        libctx, CRYPT_PKEY_RSA, CRYPT_EAL_PKEY_KEYMGMT_OPERATE + CRYPT_EAL_PKEY_CIPHER_OPERATE, "provider=kaev1");
    assert_non_null(pkey);

    assert_int_equal(RandInit(), CRYPT_SUCCESS);

    /* HiTLS pubenc, prvdec */
    assert_int_equal(CRYPT_EAL_PkeySetPub(pkey, &pubkey), CRYPT_SUCCESS);
    assert_int_equal(CRYPT_EAL_PkeySetPrv(pkey, &prvkey), CRYPT_SUCCESS);
    assert_int_equal(CRYPT_EAL_PkeyCtrl(pkey, CRYPT_CTRL_SET_RSA_RSAES_OAEP, oaepParam, 0), CRYPT_SUCCESS);
    assert_int_equal(CRYPT_EAL_PkeyCtrl(pkey, CRYPT_CTRL_SET_RSA_OAEP_LABEL, label->x, label->len), CRYPT_SUCCESS);
    assert_int_equal(CRYPT_EAL_PkeyEncrypt(pkey, plaintext->x, plaintext->len, ct, &msgLen), CRYPT_SUCCESS);
    assert_int_equal(CRYPT_EAL_PkeyDecrypt(pkey, ct, msgLen, pt, &msgLen), CRYPT_SUCCESS);
    assert_int_equal(msgLen, plaintext->len);
    assert_int_equal(memcmp(pt, plaintext->x, msgLen), 0);

    CRYPT_EAL_PkeyCtx *cpyCtx = CRYPT_EAL_ProviderPkeyNewCtx(
        libctx, CRYPT_PKEY_RSA, CRYPT_EAL_PKEY_KEYMGMT_OPERATE + CRYPT_EAL_PKEY_CIPHER_OPERATE, "provider=kaev1");
    assert_non_null(cpyCtx);

    assert_int_equal(CRYPT_EAL_PkeyCopyCtx(cpyCtx, pkey), CRYPT_SUCCESS);

    msgLen = MAX_CIPHERTEXT_LEN;
    assert_int_equal(CRYPT_EAL_PkeyEncrypt(cpyCtx, plaintext->x, plaintext->len, ct, &msgLen), CRYPT_SUCCESS);
    assert_int_equal(CRYPT_EAL_PkeyDecrypt(cpyCtx, ct, msgLen, pt, &msgLen), CRYPT_SUCCESS);

    FreeHex(n);
    FreeHex(e);
    FreeHex(d);
    FreeHex(plaintext);
    FreeHex(label);

    CRYPT_EAL_RandDeinit();
    CRYPT_EAL_PkeyFreeCtx(pkey);
    CRYPT_EAL_PkeyFreeCtx(cpyCtx);
    CRYPT_EAL_LibCtxFree(libctx);
}

int main(void)
{
    struct CMUnitTest tests[GROUP_TEST_MAX] = {NULL};
    int testCnt = 0;

    tests[testCnt++] = (struct CMUnitTest)cmocka_unit_test(SDV_KAE_RSA_ENC_PROVIDER_LOAD);
    for (size_t i = 0; i < sizeof(SDV_KAE_RSA_CRYPT_FUNC_TC001_VEC) / sizeof(SDV_KAE_RSA_CRYPT_FUNC_TC001_VEC[0]);
         i++) {
        tests[testCnt++] = (struct CMUnitTest)cmocka_unit_test_prestate(SDV_KAE_RSA_CRYPT_FUNC_TC001,
                                                                        &SDV_KAE_RSA_CRYPT_FUNC_TC001_VEC[i]);
    }
    for (size_t i = 0; i < sizeof(SDV_KAE_RSA_CRYPT_FUNC_TC002_VEC) / sizeof(SDV_KAE_RSA_CRYPT_FUNC_TC002_VEC[0]);
         i++) {
        tests[testCnt++] = (struct CMUnitTest)cmocka_unit_test_prestate(SDV_KAE_RSA_CRYPT_FUNC_TC002,
                                                                        &SDV_KAE_RSA_CRYPT_FUNC_TC002_VEC[i]);
    }
    for (size_t i = 0; i < sizeof(SDV_KAE_RSA_CRYPT_FUNC_TC003_VEC) / sizeof(SDV_KAE_RSA_CRYPT_FUNC_TC003_VEC[0]);
         i++) {
        tests[testCnt++] = (struct CMUnitTest)cmocka_unit_test_prestate(SDV_KAE_RSA_CRYPT_FUNC_TC003,
                                                                        &SDV_KAE_RSA_CRYPT_FUNC_TC003_VEC[i]);
    }
    cmocka_run_group_tests(tests, NULL, NULL);
    return 0;
}